<%@page import="wt.session.SessionServerHelper"%>
<%@page import="wt.vc.VersionReference"%>
<%@page import="wt.vc.Iterated"%>
<%@page import="wt.workflow.work.WorkItem"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="wt.fc.QueryResult"%>
<%@page import="ext.drawing.BorrowUtil"%>
<%@page import="ext.tianma.upload.MyUtil"%>
<%@page import="wt.part.WTPart"%>
<%@page import="wt.doc.WTDocument"%>
<%@page import="wt.fc.WTObject"%>
<%@page import="wt.inf.container.WTContainer"%>
<%@page import="ext.drawing.BorrowWorkflowUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page
		import="wt.method.RemoteMethodServer,
	                 ext.workflow.WorkFlowUtil,
					 java.util.*,
					 java.lang.*,
					 wt.project.*,
					 wt.workflow.engine.*,
					 wt.org.*
					 "%>
<!DOCTYPE html>

<%
	String path = request.getContextPath();
	String wid = request.getParameter("oid");

	boolean flag = SessionServerHelper.manager.setAccessEnforced(false);// 忽略权限

	String oid = "";
	String cioids = "";
	String url = "";
	String downUrl = "";
	String name = "";
	String baseHref = new wt.httpgw.URLFactory().getBaseHREF();
	WTDocument doc01 = WTDocument.newWTDocument();
	String radio0 = "";
	Boolean isEdit = true;
	Boolean b = true;

	if ("".equals(wid) || wid==null) {
		doc01 = null;

	} else {
		b = false;

		ReferenceFactory rf = new ReferenceFactory();
		WorkItem worlitem  = (WorkItem) rf.getReference(wid).getObject();
		String status  = worlitem.getStatus().toString();
		WfProcess process = MyUtil.GetWfProcess(wid);
		ProcessData processData = process.getContext();

		isEdit = (Boolean) processData.getValue("isEdit");

		if("COMPLETED".equals(status)){
			isEdit = false;
		}else{
			isEdit = true;
		}
		doc01 = (WTDocument) processData.getValue("radio01");
		radio0 = (String) processData.getValue("radio0");
	}
	ReferenceFactory rf = new ReferenceFactory();

	SessionServerHelper.manager.setAccessEnforced(flag);// 关闭权限
%>


<html>
<head>
	<meta charset="UTF-8">

	<script type="text/javascript">
		PTC.onReady(function() {
			//设置页面不可编辑
			var arr = ["radio0","upload"];

			if(false == <%=isEdit %>){
				var a = document.getElementsByTagName("input");
				for(var i = 0; i<a.length; i++) {
					var name = a[i].getAttribute("name");
					if(arr.indexOf(name)!=-1){
						//alert("name:"+name);
						a[i].setAttribute("disabled","true");
					}
				}
			}

			if(false == <%=b %>){
				setRadio("radio0","<%=radio0 %>");
				fun0("<%=radio0 %>");
			}
		});

		function setRadio(str1,str2){
			var radio = document.getElementsByName(str1);
			if(str2 == "Y"){
				radio[0].checked=true;
			} else if(str2 == "N"){
				radio[1].checked=true;
			}
		}

		function setBT(str1,str2){
			var bt = document.getElementsByName(str1);
			bt[0].value = str2;
		}

		function fun0(str) {
			var gkljpz = document.getElementById("gkljpz");
			if (str == "Y") {
				gkljpz.style.display = "block";
			} else {
				gkljpz.style.display = "none";
				gkljpz.outerHTML = gkljpz.outerHTML;

			}
		}

		function fun(str1,str2){
			var radio0 = getRadio("radio0");

			<%-- var url = '<%=path %>/netmarkets/jsp/upload/commonUpload.jsp?wid=<%=wid %>&docKey='+str;
            url = url+"&radio0="+radio0;
            window.open(url, '_blank','resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,status=no'); --%>

			var values = {
				"radio0": radio0,
			};

			values = O2String(values);
			var str = document.getElementById(str2).value;
			if (str == "") {
				alert("上传文档不能为空！");
			} else {
				var url = '<%=path %>/netmarkets/jsp/upload/commonHandle.jsp?wid=<%=wid %>&docKey=' +str1+ '&values=' + values;
				var a = document.getElementById('form'+str1);
				//  alert("a"+a);
				//  alert(url);
				document.getElementById('form'+str1).action = url;
				document.getElementById('form'+str1).submit();
				document.getElementById("box").innerText="正在导入，请稍候......";

			}
		}

		function getRadio(radio){
			var radios = document.getElementsByName(radio);
			var selectvalue = null;   //  selectvalue为radio中选中的值
			for(var i=0;i<radios.length;i++){
				if(radios[i].checked==true) {
					selectvalue=radios[i].value;
					break;
				}
			}
			return selectvalue;
		}

		function O2String(O) {
			//return JSON.stringify(jsonobj);
			var S = [];
			var J = "";
			if (Object.prototype.toString.apply(O) === '[object Array]') {
				for (var i = 0; i < O.length; i++)
					S.push(O2String(O[i]));
				J = '[' + S.join(',') + ']';
			}
			else if (Object.prototype.toString.apply(O) === '[object Date]') {
				J = "new Date(" + O.getTime() + ")";
			}
			else if (Object.prototype.toString.apply(O) === '[object RegExp]' || Object.prototype.toString.apply(O) === '[object Function]') {
				J = O.toString();
			}
			else if (Object.prototype.toString.apply(O) === '[object Object]') {
				for (var i in O) {
					O[i] = typeof (O[i]) == 'string' ? '"' + O[i] + '"' : (typeof (O[i]) === 'object' ? O2String(O[i]) : O[i]);
					S.push('"' + i + '":' + O[i]);
				}
				J = '{' + S.join(',') + '}';
			}
			return J;
		};
	</script>
	<title>xxPart</title>


	<style type="text/css">

		.fileinput-button {
			position: relative;
			display: inline-block;
			overflow: hidden;
			background: #A9A9A9;
			cursor: pointer;
		}

		.fileinput-button input{
			position: absolute;
			left: 0px;
			top: 0px;
			opacity: 0;
			-ms-filter: 'alpha(opacity=0)';

		}

		.liA {
			width: 100%;
			list-style: none;
			padding-bottom: 23px;
		}

		.divA, .divB {
			width: 50%;
			display: inline-block;
			float: left;
		}

		#special {
			font-weight: normal;
			color: #464646;
		}
	</style>
</head>


<body>
<div id="box">
	<font style="font-weight: bold;font-size: 12px;">消显类型：</font>
	<ul>
		<li><span> &nbsp;</span></li>
		<li class="liA">
			<div class="divA">1.工控零件批准是否通过？</div>
			<div class="divB">
				<div class="divB1" style="float: left;">
					<font style="color: red; font-size: 14px;">*&nbsp;&nbsp;</font>
					<input type="radio" name="radio0" value="Y" onclick="fun0('Y')">Y
					<input type="radio" name="radio0" value="N" onclick="fun0('N')">N
				</div>

				<div class="divB2" style="float: left; display: none;" id="gkljpz">
					<form id="Test" method="POST" ENCTYPE="multipart/form-data">
					</form>
					<form id="formradio01" method="POST" ENCTYPE="multipart/form-data">

						<%
							if (doc01 == null) {

						%>

						&nbsp;&nbsp;
						<span class="fileinput-button">
				            <span>上传(批准报告)</span>
				            <input id="in011" type="file" name="upload" onchange="fun('radio01','in011')">
				        </span>
						<%
						} else {
							name = doc01.getName();
							oid = rf.getReferenceString(doc01);
							cioids = MyUtil.getPrimaryId(doc01);
							url = baseHref + "app/#ptc1/tcomp/infoPage?oid=" + oid;
							downUrl = baseHref + "servlet/AttachmentsDownloadDirectionServlet?oid=" +oid+ "&oid=" +cioids +"&role=PRIMARY";
						%>

						&nbsp;&nbsp;
						<span class="fileinput-button">
				            <span>重新上传</span>
				            <input id="in012" type="file" name="upload" onchange="fun('radio01','in012')">
				        </span>
						&nbsp;
						<a href="<%=url%>" target="_blank"><%=name%></a>
						&nbsp;
						<a href="<%=downUrl%>" target="_blank">下载</a>

						<%
							}
						%>
					</form>
				</div>

			</div>
		</li>
	</ul>
</div>

</body>
</html>